/**
 * Created by 白雨浓 on 2018/1/16 12:50.
 */

export default {

    convert(self, table){

        let clsName = self.$str.toCamel(table);
        clsName = clsName.substring(0, 1).toUpperCase() + clsName.substring(1);

        return `package ${self.config.packageName}.convert;

import ${self.config.packageName}.bean.${clsName}Bean;
import ${self.config.packageName}.convert.base.BaseConvert;
import ${self.config.packageName}.entity.${clsName}Entity;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * ${self.config.packageName}.convert
 *
 * @author 白雨浓
 * date: ${self.$date.format(new Date(), 'yyyy/MM/dd hh:mm')}
 * content: 转换
 */
public class ${clsName}Convert extends BaseConvert {

    public static ${clsName}Bean convertToModel(${clsName}Entity entity) {
        if (entity == null)
            return null;
        return mapper.map(entity, ${clsName}Bean.class);
    }

    public static ${clsName}Entity convertToEntity(${clsName}Bean bean) {
        if (bean == null)
            return null;
        return mapper.map(bean, ${clsName}Entity.class);
    }

    public static List<${clsName}Bean> convertToModelList(List<${clsName}Entity> list) {
        List<${clsName}Bean> beanList = new ArrayList<>();
        list.parallelStream().forEachOrdered(entity -> beanList.add(convertToModel(entity)));
        return beanList;
    }

    public static List<${clsName}Bean> convertToModelList(List<${clsName}Entity> list, Consumer<${clsName}Entity> consumer) {
        List<${clsName}Bean> beanList = new ArrayList<>();
        list.parallelStream().forEachOrdered(entity -> {
            consumer.accept(entity);
            beanList.add(convertToModel(entity));
        });
        return beanList;
    }

    public static List<${clsName}Entity> convertToEntityList(List<${clsName}Bean> list) {
        List<${clsName}Entity> entityList = new ArrayList<>();
        list.parallelStream().forEachOrdered(bean -> entityList.add(convertToEntity(bean)));
        return entityList;
    }

    public static List<${clsName}Entity> convertToEntityList(List<${clsName}Bean> list, Consumer<${clsName}Bean> consumer) {
        List<${clsName}Entity> entityList = new ArrayList<>();
        list.parallelStream().forEachOrdered(bean -> {
            consumer.accept(bean);
            entityList.add(convertToEntity(bean));
        });
        return entityList;
    }
}
        `;
    }
}